<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>CKEDITOR.dom.text</title>
	<link rel="stylesheet" type="text/css" href="../../test.css" />
	<script type="text/javascript" src="../../../ckeditor.js"></script>
	<script type="text/javascript" src="../../test.js"></script>
	<script type="text/javascript">
	//<![CDATA[

var tc;
CKEDITOR.test.addTestCase( tc = (function()
{
	// Local reference to the "assert" object.
	var assert = CKEDITOR.test.assert;

	return {

		test_substring1 : function()
		{
			var text = new CKEDITOR.dom.text( '0123456789' );

			assert.areSame( '123', text.substring( 1, 4 ) );
		},

		test_substring2 : function()
		{
			var text = new CKEDITOR.dom.text( '0123456789' );

			assert.areSame( '56789', text.substring( 5 ) );
		},

		test_substring3 : function()
		{
			var text = new CKEDITOR.dom.text( '0123456789' );

			assert.areSame( '', text.substring( 1,1 ) );
		},

		test_substring4 : function()
		{
			var text = new CKEDITOR.dom.text( '0123456789' );

			assert.areSame( '012', text.substring( -10,3 ) );
		},

		test_substring5 : function()
		{
			var text = new CKEDITOR.dom.text( '0123456789' );

			assert.areSame( '89', text.substring( 8,100 ) );
		},

		test_substring6 : function()
		{
			var text = new CKEDITOR.dom.text( '0123456789' );

			assert.areSame( '234', text.substring( 5,2 ) );
		},

		test_split1 : function()
		{
			var div = CKEDITOR.document.getById( 'playground' );
			div.setHtml( '01234' );

			var text = div.getFirst(),
				next = text.split( 3 );

			assert.areSame( '012', text.getText(), 'text.getText() is wrong' );
			assert.areSame( '34', next.getText(), 'next.getText() is wrong' );

			assert.areSame( div.$, next.$.parentNode, 'parentNode is wrong' );
			assert.areSame( text.$, next.$.previousSibling, 'sibling is wrong' );
		},

		test_split2 : function()
		{
			var div = CKEDITOR.document.getById( 'playground' );
			div.setHtml( '01234' );

			var text = div.getFirst(),
				next = text.split( 5 );

			assert.areSame( '01234', text.getText(), 'text.getText() is wrong' );
			assert.areSame( '', next.getText(), 'next.getText() is wrong' );

			assert.areSame( div.$, next.$.parentNode, 'parentNode is wrong' );
			assert.areSame( text.$, next.$.previousSibling, 'sibling is wrong' );
		},

		test_split3 : function()
		{
			var div = CKEDITOR.document.getById( 'playground' );
			div.setHtml( '01234' );

			var text = div.getFirst(),
				next = text.split( 0 );

			assert.areSame( '', text.getText(), 'text.getText() is wrong' );
			assert.areSame( '01234', next.getText(), 'next.getText() is wrong' );

			assert.areSame( div.$, next.$.parentNode, 'parentNode is wrong' );
			assert.areSame( text.$, next.$.previousSibling, 'sibling is wrong' );
		},

		test_split_3436 : function()
		{
			var parent = CKEDITOR.document.getById( 'playground2' );
			parent.setHtml( 'A B <b>C </b>D E' );
			parent.getFirst().split( 2 );	// Right before "B"
			parent.getChildren().getItem( 3 ).split( 2 );	// Right before "E"
			assert.areSame( 5, parent.getChildren().count(), 'Child nodes num doesn\'t match after split' );
		},

		name : document.title
	};
})() );

//window.onload = tc.test_split_3436;

	//]]>
	</script>
</head>
<body>
	<p id="playground"></p>
	<p id="playground2"></p>
</body>
</html>
